<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>切换图片</title>
    <script>
        window.onload=function () {
        var total=document.getElementById("total");
            total.style.backgroundImage="url(../imagconman/荷花.png)";
            total.style.backgroundRepeat = "no-repeat";//背景图片不重复 整张图片填满整个背景
         var index=0;
         var imgArr=["../imagconman/荷花.png","../imagconman/蝗虫.png","../imagconman/2020318.png","../imagconman/向日葵.png"];
        div01.onclick=function () {
            index--;
            if (index<0){
                index=imgArr.length-1;
            }
            total.style.backgroundImage="url("+imgArr[index]+")";// "url(../imagconman/荷花.png)"
            };

        div02.onclick=function () {
            index++;
            if (index>imgArr.length-1){
                index=0
            }
            total.style.backgroundImage="url("+imgArr[index]+")";
        };
        }
    </script>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        #total{
            width: 340px;
            height: 300px;
           /*background: #cccccc;*/
            margin: 0 auto;
        }
        #total:hover{
            cursor: pointer;
        }
        #div01{
            width: 170px;
            height: 300px;
            background-image: url("../imagconman/left.png");
            display: inline-block;

        }
        #div02{
            width: 170px;
            height: 300px;
            background-image: url("../imagconman/right.png");
            float: right;
        }

    </style>
</head>
<body>
<div id="total">
    <div id="div01" >

    </div>
    <div id="div02">

    </div>
</div>
</body>
</html>